

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>saml2.settings &mdash; SAML Python library classes and methods</title>

    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />

    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="SAML Python library classes and methods" href="../../index.html" />
    <link rel="up" title="Class code" href="../index.html" />
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Class Index"
             >modules</a> |</li>
        <li><a href="../../index.html">SAML Python library classes and methods</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Class code</a> &raquo;</li>
      </ul>
    </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">

  <h1>Source code for saml2.settings</h1><div class="highlight"><pre>
<span class="c"># -*- coding: utf-8 -*-</span>


<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">from</span> <span class="nn">os.path</span> <span class="kn">import</span> <span class="n">dirname</span><span class="p">,</span> <span class="n">exists</span><span class="p">,</span> <span class="n">join</span><span class="p">,</span> <span class="n">sep</span>
<span class="kn">from</span> <span class="nn">xml.dom.minidom</span> <span class="kn">import</span> <span class="n">Document</span>

<span class="kn">from</span> <span class="nn">saml2.constants</span> <span class="kn">import</span> <span class="n">OneLogin_Saml2_Constants</span>
<span class="kn">from</span> <span class="nn">saml2.errors</span> <span class="kn">import</span> <span class="n">OneLogin_Saml2_Error</span>
<span class="kn">from</span> <span class="nn">saml2.metadata</span> <span class="kn">import</span> <span class="n">OneLogin_Saml2_Metadata</span>
<span class="kn">from</span> <span class="nn">saml2.utils</span> <span class="kn">import</span> <span class="n">OneLogin_Saml2_Utils</span>


<span class="c"># Regex from Django Software Foundation and individual contributors.</span>
<span class="c"># Released under a BSD 3-Clause License</span>
<span class="n">url_regex</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span>
    <span class="s">r&#39;^(?:[a-z0-9\.\-]*)://&#39;</span>  <span class="c"># scheme is validated separately</span>
    <span class="s">r&#39;(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|&#39;</span>  <span class="c"># domain...</span>
    <span class="s">r&#39;localhost|&#39;</span>  <span class="c"># localhost...</span>
    <span class="s">r&#39;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|&#39;</span>  <span class="c"># ...or ipv4</span>
    <span class="s">r&#39;\[?[A-F0-9]*:[A-F0-9:]+\]?)&#39;</span>  <span class="c"># ...or ipv6</span>
    <span class="s">r&#39;(?::\d+)?&#39;</span>  <span class="c"># optional port</span>
    <span class="s">r&#39;(?:/?|[/?]\S+)$&#39;</span><span class="p">,</span> <span class="n">re</span><span class="o">.</span><span class="n">IGNORECASE</span><span class="p">)</span>
<span class="n">url_schemes</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;http&#39;</span><span class="p">,</span> <span class="s">&#39;https&#39;</span><span class="p">,</span> <span class="s">&#39;ftp&#39;</span><span class="p">,</span> <span class="s">&#39;ftps&#39;</span><span class="p">]</span>


<div class="viewcode-block" id="validate_url"><a class="viewcode-back" href="../../saml2.html#saml2.settings.validate_url">[docs]</a><span class="k">def</span> <span class="nf">validate_url</span><span class="p">(</span><span class="n">url</span><span class="p">):</span>
    <span class="n">scheme</span> <span class="o">=</span> <span class="n">url</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;://&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="k">if</span> <span class="n">scheme</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">url_schemes</span><span class="p">:</span>
        <span class="k">return</span> <span class="bp">False</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="nb">bool</span><span class="p">(</span><span class="n">url_regex</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">url</span><span class="p">)):</span>
        <span class="k">return</span> <span class="bp">False</span>
    <span class="k">return</span> <span class="bp">True</span>

</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings">[docs]</a><span class="k">class</span> <span class="nc">OneLogin_Saml2_Settings</span><span class="p">:</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">settings</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">custom_base_path</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initializes the settings:</span>
<span class="sd">        - Sets the paths of the different folders</span>
<span class="sd">        - Loads settings info from settings file or array/object provided</span>

<span class="sd">        :param settings: SAML Toolkit Settings</span>
<span class="sd">        :type settings: dict|object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__paths</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__strict</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__debug</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__sp</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__idp</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__contacts</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__organization</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__errors</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__load_paths</span><span class="p">(</span><span class="n">base_path</span><span class="o">=</span><span class="n">custom_base_path</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__update_paths</span><span class="p">(</span><span class="n">settings</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">settings</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__load_settings_from_file</span><span class="p">():</span>
                <span class="k">raise</span> <span class="n">OneLogin_Saml2_Error</span><span class="p">(</span>
                    <span class="s">&#39;Invalid file settings: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span>
                    <span class="n">OneLogin_Saml2_Error</span><span class="o">.</span><span class="n">SETTINGS_INVALID</span><span class="p">,</span>
                    <span class="s">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__errors</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__add_default_values</span><span class="p">()</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">settings</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__load_settings_from_dict</span><span class="p">(</span><span class="n">settings</span><span class="p">):</span>
                <span class="k">raise</span> <span class="n">OneLogin_Saml2_Error</span><span class="p">(</span>
                    <span class="s">&#39;Invalid dict settings: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span>
                    <span class="n">OneLogin_Saml2_Error</span><span class="o">.</span><span class="n">SETTINGS_INVALID</span><span class="p">,</span>
                    <span class="s">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__errors</span><span class="p">)</span>
                <span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&#39;Unsupported settings object&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">format_idp_cert</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">__load_paths</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">base_path</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sets the paths of the different folders</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">base_path</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">base_path</span> <span class="o">=</span> <span class="n">dirname</span><span class="p">(</span><span class="n">dirname</span><span class="p">(</span><span class="n">dirname</span><span class="p">(</span><span class="n">__file__</span><span class="p">)))</span>
        <span class="n">base_path</span> <span class="o">+=</span> <span class="n">sep</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__paths</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;base&#39;</span><span class="p">:</span> <span class="n">base_path</span><span class="p">,</span>
            <span class="s">&#39;cert&#39;</span><span class="p">:</span> <span class="n">base_path</span> <span class="o">+</span> <span class="s">&#39;certs&#39;</span> <span class="o">+</span> <span class="n">sep</span><span class="p">,</span>
            <span class="s">&#39;lib&#39;</span><span class="p">:</span> <span class="n">base_path</span> <span class="o">+</span> <span class="s">&#39;lib&#39;</span> <span class="o">+</span> <span class="n">sep</span><span class="p">,</span>
            <span class="s">&#39;extlib&#39;</span><span class="p">:</span> <span class="n">base_path</span> <span class="o">+</span> <span class="s">&#39;extlib&#39;</span> <span class="o">+</span> <span class="n">sep</span><span class="p">,</span>
        <span class="p">}</span>

    <span class="k">def</span> <span class="nf">__update_paths</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">settings</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set custom paths if necessary</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">settings</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="k">return</span>

        <span class="k">if</span> <span class="s">&#39;custom_base_path&#39;</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">:</span>
            <span class="n">base_path</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;custom_base_path&#39;</span><span class="p">]</span>
            <span class="n">base_path</span> <span class="o">=</span> <span class="n">join</span><span class="p">(</span><span class="n">dirname</span><span class="p">(</span><span class="n">__file__</span><span class="p">),</span> <span class="n">base_path</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__load_paths</span><span class="p">(</span><span class="n">base_path</span><span class="p">)</span>

<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_base_path"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_base_path">[docs]</a>    <span class="k">def</span> <span class="nf">get_base_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns base path</span>

<span class="sd">        :return: The base toolkit folder path</span>
<span class="sd">        :rtype: string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__paths</span><span class="p">[</span><span class="s">&#39;base&#39;</span><span class="p">]</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_cert_path"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_cert_path">[docs]</a>    <span class="k">def</span> <span class="nf">get_cert_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns cert path</span>

<span class="sd">        :return: The cert folder path</span>
<span class="sd">        :rtype: string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__paths</span><span class="p">[</span><span class="s">&#39;cert&#39;</span><span class="p">]</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_lib_path"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_lib_path">[docs]</a>    <span class="k">def</span> <span class="nf">get_lib_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns lib path</span>

<span class="sd">        :return: The library folder path</span>
<span class="sd">        :rtype: string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__paths</span><span class="p">[</span><span class="s">&#39;lib&#39;</span><span class="p">]</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_ext_lib_path"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_ext_lib_path">[docs]</a>    <span class="k">def</span> <span class="nf">get_ext_lib_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns external lib path</span>

<span class="sd">        :return: The external library folder path</span>
<span class="sd">        :rtype: string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__paths</span><span class="p">[</span><span class="s">&#39;extlib&#39;</span><span class="p">]</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_schemas_path"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_schemas_path">[docs]</a>    <span class="k">def</span> <span class="nf">get_schemas_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns schema path</span>

<span class="sd">        :return: The schema folder path</span>
<span class="sd">        :rtype: string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__paths</span><span class="p">[</span><span class="s">&#39;lib&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="s">&#39;schemas/&#39;</span>
</div>
    <span class="k">def</span> <span class="nf">__load_settings_from_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">settings</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Loads settings info from a settings Dict</span>

<span class="sd">        :param settings: SAML Toolkit Settings</span>
<span class="sd">        :type settings: dict</span>

<span class="sd">        :returns: True if the settings info is valid</span>
<span class="sd">        :rtype: boolean</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">errors</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_settings</span><span class="p">(</span><span class="n">settings</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">errors</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__errors</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__sp</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;sp&#39;</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__idp</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;idp&#39;</span><span class="p">]</span>

            <span class="k">if</span> <span class="s">&#39;strict&#39;</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__strict</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;strict&#39;</span><span class="p">]</span>
            <span class="k">if</span> <span class="s">&#39;debug&#39;</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__debug</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;debug&#39;</span><span class="p">]</span>
            <span class="k">if</span> <span class="s">&#39;security&#39;</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__security</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;security&#39;</span><span class="p">]</span>
            <span class="k">if</span> <span class="s">&#39;contactPerson&#39;</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__contacts</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;contactPerson&#39;</span><span class="p">]</span>
            <span class="k">if</span> <span class="s">&#39;organization&#39;</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__organization</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;organization&#39;</span><span class="p">]</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">__add_default_values</span><span class="p">()</span>
            <span class="k">return</span> <span class="bp">True</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__errors</span> <span class="o">=</span> <span class="n">errors</span>
        <span class="k">return</span> <span class="bp">False</span>

    <span class="k">def</span> <span class="nf">__load_settings_from_file</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Loads settings info from the settings json file</span>

<span class="sd">        :returns: True if the settings info is valid</span>
<span class="sd">        :rtype: boolean</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">filename</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_base_path</span><span class="p">()</span> <span class="o">+</span> <span class="s">&#39;settings.json&#39;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">exists</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
            <span class="k">raise</span> <span class="n">OneLogin_Saml2_Error</span><span class="p">(</span>
                <span class="s">&#39;Settings file not found: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span>
                <span class="n">OneLogin_Saml2_Error</span><span class="o">.</span><span class="n">SETTINGS_FILE_NOT_FOUND</span><span class="p">,</span>
                <span class="n">filename</span>
            <span class="p">)</span>

        <span class="c"># In the php toolkit instead of being a json file it is a php file and</span>
        <span class="c"># it is directly included</span>
        <span class="n">json_data</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span>
        <span class="n">settings</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">json_data</span><span class="p">)</span>
        <span class="n">json_data</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="n">advanced_filename</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_base_path</span><span class="p">()</span> <span class="o">+</span> <span class="s">&#39;advanced_settings.json&#39;</span>
        <span class="k">if</span> <span class="n">exists</span><span class="p">(</span><span class="n">advanced_filename</span><span class="p">):</span>
            <span class="n">json_data</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">advanced_filename</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span>
            <span class="n">settings</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">json_data</span><span class="p">))</span>  <span class="c"># Merge settings</span>
            <span class="n">json_data</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__load_settings_from_dict</span><span class="p">(</span><span class="n">settings</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__add_default_values</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add default values if the settings info is not complete</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="s">&#39;binding&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__sp</span><span class="p">[</span><span class="s">&#39;assertionConsumerService&#39;</span><span class="p">]:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__sp</span><span class="p">[</span><span class="s">&#39;assertionConsumerService&#39;</span><span class="p">][</span><span class="s">&#39;binding&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">OneLogin_Saml2_Constants</span><span class="o">.</span><span class="n">BINDING_HTTP_POST</span>
        <span class="k">if</span> <span class="s">&#39;singleLogoutService&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__sp</span> <span class="ow">and</span> <span class="s">&#39;binding&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__sp</span><span class="p">[</span><span class="s">&#39;singleLogoutService&#39;</span><span class="p">]:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__sp</span><span class="p">[</span><span class="s">&#39;singleLogoutService&#39;</span><span class="p">][</span><span class="s">&#39;binding&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">OneLogin_Saml2_Constants</span><span class="o">.</span><span class="n">BINDING_HTTP_REDIRECT</span>

        <span class="c"># Related to nameID</span>
        <span class="k">if</span> <span class="s">&#39;NameIDFormat&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__sp</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__sp</span><span class="p">[</span><span class="s">&#39;NameIDFormat&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">OneLogin_Saml2_Constants</span><span class="o">.</span><span class="n">NAMEID_PERSISTENT</span>
        <span class="k">if</span> <span class="s">&#39;nameIdEncrypted&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;nameIdEncrypted&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>

        <span class="c"># Sign provided</span>
        <span class="k">if</span> <span class="s">&#39;authnRequestsSigned&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;authnRequestsSigned&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">if</span> <span class="s">&#39;logoutRequestSigned&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;logoutRequestSigned&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">if</span> <span class="s">&#39;logoutResponseSigned&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;logoutResponseSigned&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">if</span> <span class="s">&#39;signMetadata&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;signMetadata&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>

        <span class="c"># Sign expected</span>
        <span class="k">if</span> <span class="s">&#39;wantMessagesSigned&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;wantMessagesSigned&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">if</span> <span class="s">&#39;wantAssertionsSigned&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;wantAssertionsSigned&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>

        <span class="c"># Encrypt expected</span>
        <span class="k">if</span> <span class="s">&#39;wantAssertionsEncrypted&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;wantAssertionsEncrypted&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">if</span> <span class="s">&#39;wantNameIdEncrypted&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;wantNameIdEncrypted&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>

        <span class="k">if</span> <span class="s">&#39;x509cert&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__idp</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__idp</span><span class="p">[</span><span class="s">&#39;x509cert&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
        <span class="k">if</span> <span class="s">&#39;certFingerprint&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__idp</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__idp</span><span class="p">[</span><span class="s">&#39;certFingerprint&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>

<div class="viewcode-block" id="OneLogin_Saml2_Settings.check_settings"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.check_settings">[docs]</a>    <span class="k">def</span> <span class="nf">check_settings</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">settings</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Checks the settings info.</span>

<span class="sd">        :param settings: Dict with settings data</span>
<span class="sd">        :type settings: dict</span>

<span class="sd">        :returns: Errors found on the settings data</span>
<span class="sd">        :rtype: list</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">settings</span><span class="p">,</span> <span class="nb">dict</span><span class="p">)</span>

        <span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">settings</span><span class="p">,</span> <span class="nb">dict</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">settings</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;invalid_syntax&#39;</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">errors</span>

        <span class="k">if</span> <span class="s">&#39;idp&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">settings</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">settings</span><span class="p">[</span><span class="s">&#39;idp&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;idp_not_found&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">idp</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;idp&#39;</span><span class="p">]</span>
            <span class="k">if</span> <span class="s">&#39;entityId&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">idp</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">idp</span><span class="p">[</span><span class="s">&#39;entityId&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;idp_entityId_not_found&#39;</span><span class="p">)</span>

            <span class="k">if</span> <span class="p">(</span><span class="s">&#39;singleSignOnService&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">idp</span> <span class="ow">or</span>
                <span class="s">&#39;url&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">idp</span><span class="p">[</span><span class="s">&#39;singleSignOnService&#39;</span><span class="p">]</span> <span class="ow">or</span>
                    <span class="nb">len</span><span class="p">(</span><span class="n">idp</span><span class="p">[</span><span class="s">&#39;singleSignOnService&#39;</span><span class="p">][</span><span class="s">&#39;url&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">):</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;idp_sso_not_found&#39;</span><span class="p">)</span>
            <span class="k">elif</span> <span class="ow">not</span> <span class="n">validate_url</span><span class="p">(</span><span class="n">idp</span><span class="p">[</span><span class="s">&#39;singleSignOnService&#39;</span><span class="p">][</span><span class="s">&#39;url&#39;</span><span class="p">]):</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;idp_sso_url_invalid&#39;</span><span class="p">)</span>

            <span class="k">if</span> <span class="p">(</span><span class="s">&#39;singleLogoutService&#39;</span> <span class="ow">in</span> <span class="n">idp</span> <span class="ow">and</span>
                <span class="s">&#39;url&#39;</span> <span class="ow">in</span> <span class="n">idp</span><span class="p">[</span><span class="s">&#39;singleLogoutService&#39;</span><span class="p">]</span> <span class="ow">and</span>
                <span class="nb">len</span><span class="p">(</span><span class="n">idp</span><span class="p">[</span><span class="s">&#39;singleLogoutService&#39;</span><span class="p">][</span><span class="s">&#39;url&#39;</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span>
                    <span class="ow">not</span> <span class="n">validate_url</span><span class="p">(</span><span class="n">idp</span><span class="p">[</span><span class="s">&#39;singleLogoutService&#39;</span><span class="p">][</span><span class="s">&#39;url&#39;</span><span class="p">])):</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;idp_slo_url_invalid&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="s">&#39;sp&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">settings</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">settings</span><span class="p">[</span><span class="s">&#39;sp&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;sp_not_found&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">sp</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;sp&#39;</span><span class="p">]</span>
            <span class="n">security</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">if</span> <span class="s">&#39;security&#39;</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">:</span>
                <span class="n">security</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;security&#39;</span><span class="p">]</span>

            <span class="k">if</span> <span class="s">&#39;entityId&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">sp</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">sp</span><span class="p">[</span><span class="s">&#39;entityId&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;sp_entityId_not_found&#39;</span><span class="p">)</span>

            <span class="k">if</span> <span class="p">(</span><span class="s">&#39;assertionConsumerService&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">sp</span> <span class="ow">or</span>
                <span class="s">&#39;url&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">sp</span><span class="p">[</span><span class="s">&#39;assertionConsumerService&#39;</span><span class="p">]</span> <span class="ow">or</span>
                    <span class="nb">len</span><span class="p">(</span><span class="n">sp</span><span class="p">[</span><span class="s">&#39;assertionConsumerService&#39;</span><span class="p">][</span><span class="s">&#39;url&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">):</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;sp_acs_not_found&#39;</span><span class="p">)</span>
            <span class="k">elif</span> <span class="ow">not</span> <span class="n">validate_url</span><span class="p">(</span><span class="n">sp</span><span class="p">[</span><span class="s">&#39;assertionConsumerService&#39;</span><span class="p">][</span><span class="s">&#39;url&#39;</span><span class="p">]):</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;sp_acs_url_invalid&#39;</span><span class="p">)</span>

            <span class="k">if</span> <span class="p">(</span><span class="s">&#39;singleLogoutService&#39;</span> <span class="ow">in</span> <span class="n">sp</span> <span class="ow">and</span>
                <span class="s">&#39;url&#39;</span> <span class="ow">in</span> <span class="n">sp</span><span class="p">[</span><span class="s">&#39;singleLogoutService&#39;</span><span class="p">]</span> <span class="ow">and</span>
                <span class="nb">len</span><span class="p">(</span><span class="n">sp</span><span class="p">[</span><span class="s">&#39;singleLogoutService&#39;</span><span class="p">][</span><span class="s">&#39;url&#39;</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span>
                    <span class="ow">not</span> <span class="n">validate_url</span><span class="p">(</span><span class="n">sp</span><span class="p">[</span><span class="s">&#39;singleLogoutService&#39;</span><span class="p">][</span><span class="s">&#39;url&#39;</span><span class="p">])):</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;sp_sls_url_invalid&#39;</span><span class="p">)</span>

            <span class="k">if</span> <span class="s">&#39;signMetadata&#39;</span> <span class="ow">in</span> <span class="n">security</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">security</span><span class="p">[</span><span class="s">&#39;signMetadata&#39;</span><span class="p">],</span> <span class="nb">dict</span><span class="p">):</span>
                <span class="k">if</span> <span class="p">(</span><span class="s">&#39;keyFileName&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">security</span><span class="p">[</span><span class="s">&#39;signMetadata&#39;</span><span class="p">]</span> <span class="ow">or</span>
                        <span class="s">&#39;certFileName&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">security</span><span class="p">[</span><span class="s">&#39;signMetadata&#39;</span><span class="p">]):</span>
                    <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;sp_signMetadata_invalid&#39;</span><span class="p">)</span>

            <span class="k">if</span> <span class="p">(((</span><span class="s">&#39;authnRequestsSigned&#39;</span> <span class="ow">in</span> <span class="n">security</span> <span class="ow">and</span> <span class="n">security</span><span class="p">[</span><span class="s">&#39;authnRequestsSigned&#39;</span><span class="p">])</span> <span class="ow">or</span>
                 <span class="p">(</span><span class="s">&#39;logoutRequestSigned&#39;</span> <span class="ow">in</span> <span class="n">security</span> <span class="ow">and</span> <span class="n">security</span><span class="p">[</span><span class="s">&#39;logoutRequestSigned&#39;</span><span class="p">])</span> <span class="ow">or</span>
                 <span class="p">(</span><span class="s">&#39;logoutResponseSigned&#39;</span> <span class="ow">in</span> <span class="n">security</span> <span class="ow">and</span> <span class="n">security</span><span class="p">[</span><span class="s">&#39;logoutResponseSigned&#39;</span><span class="p">])</span> <span class="ow">or</span>
                 <span class="p">(</span><span class="s">&#39;wantAssertionsEncrypted&#39;</span> <span class="ow">in</span> <span class="n">security</span> <span class="ow">and</span> <span class="n">security</span><span class="p">[</span><span class="s">&#39;wantAssertionsEncrypted&#39;</span><span class="p">])</span> <span class="ow">or</span>
                 <span class="p">(</span><span class="s">&#39;wantNameIdEncrypted&#39;</span> <span class="ow">in</span> <span class="n">security</span> <span class="ow">and</span> <span class="n">security</span><span class="p">[</span><span class="s">&#39;wantNameIdEncrypted&#39;</span><span class="p">]))</span> <span class="ow">and</span>
                    <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_sp_certs</span><span class="p">()):</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;sp_cert_not_found_and_required&#39;</span><span class="p">)</span>

            <span class="n">exists_X509</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;idp&#39;</span> <span class="ow">in</span> <span class="n">settings</span> <span class="ow">and</span>
                           <span class="s">&#39;x509cert&#39;</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;idp&#39;</span><span class="p">]</span> <span class="ow">and</span>
                           <span class="nb">len</span><span class="p">(</span><span class="n">settings</span><span class="p">[</span><span class="s">&#39;idp&#39;</span><span class="p">][</span><span class="s">&#39;x509cert&#39;</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span>
            <span class="n">exists_fingerprint</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;idp&#39;</span> <span class="ow">in</span> <span class="n">settings</span> <span class="ow">and</span>
                                  <span class="s">&#39;certFingerprint&#39;</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;idp&#39;</span><span class="p">]</span> <span class="ow">and</span>
                                  <span class="nb">len</span><span class="p">(</span><span class="n">settings</span><span class="p">[</span><span class="s">&#39;idp&#39;</span><span class="p">][</span><span class="s">&#39;certFingerprint&#39;</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span>
            <span class="k">if</span> <span class="p">(((</span><span class="s">&#39;wantAssertionsSigned&#39;</span> <span class="ow">in</span> <span class="n">security</span> <span class="ow">and</span> <span class="n">security</span><span class="p">[</span><span class="s">&#39;wantAssertionsSigned&#39;</span><span class="p">])</span> <span class="ow">or</span>
                 <span class="p">(</span><span class="s">&#39;wantMessagesSigned&#39;</span> <span class="ow">in</span> <span class="n">security</span> <span class="ow">and</span> <span class="n">security</span><span class="p">[</span><span class="s">&#39;wantMessagesSigned&#39;</span><span class="p">]))</span> <span class="ow">and</span>
                    <span class="ow">not</span><span class="p">(</span><span class="n">exists_X509</span> <span class="ow">or</span> <span class="n">exists_fingerprint</span><span class="p">)):</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;idp_cert_or_fingerprint_not_found_and_required&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="p">(</span><span class="s">&#39;nameIdEncrypted&#39;</span> <span class="ow">in</span> <span class="n">security</span> <span class="ow">and</span> <span class="n">security</span><span class="p">[</span><span class="s">&#39;nameIdEncrypted&#39;</span><span class="p">])</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">exists_X509</span><span class="p">:</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;idp_cert_not_found_and_required&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="s">&#39;contactPerson&#39;</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">:</span>
            <span class="n">types</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;contactPerson&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
            <span class="n">valid_types</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;technical&#39;</span><span class="p">,</span> <span class="s">&#39;support&#39;</span><span class="p">,</span> <span class="s">&#39;administrative&#39;</span><span class="p">,</span> <span class="s">&#39;billing&#39;</span><span class="p">,</span> <span class="s">&#39;other&#39;</span><span class="p">]</span>
            <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">t</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">valid_types</span><span class="p">:</span>
                    <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;contact_type_invalid&#39;</span><span class="p">)</span>
                    <span class="k">break</span>

            <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;contactPerson&#39;</span><span class="p">]:</span>
                <span class="n">contact</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;contactPerson&#39;</span><span class="p">][</span><span class="n">t</span><span class="p">]</span>
                <span class="k">if</span> <span class="p">((</span><span class="s">&#39;givenName&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">contact</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">contact</span><span class="p">[</span><span class="s">&#39;givenName&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span>
                        <span class="p">(</span><span class="s">&#39;emailAddress&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">contact</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">contact</span><span class="p">[</span><span class="s">&#39;emailAddress&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)):</span>
                    <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;contact_not_enought_data&#39;</span><span class="p">)</span>
                    <span class="k">break</span>

        <span class="k">if</span> <span class="s">&#39;organization&#39;</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;organization&#39;</span><span class="p">]:</span>
                <span class="n">organization</span> <span class="o">=</span> <span class="n">settings</span><span class="p">[</span><span class="s">&#39;organization&#39;</span><span class="p">][</span><span class="n">o</span><span class="p">]</span>
                <span class="k">if</span> <span class="p">((</span><span class="s">&#39;name&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">organization</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">organization</span><span class="p">[</span><span class="s">&#39;name&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span>
                    <span class="p">(</span><span class="s">&#39;displayname&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">organization</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">organization</span><span class="p">[</span><span class="s">&#39;displayname&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span>
                        <span class="p">(</span><span class="s">&#39;url&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">organization</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">organization</span><span class="p">[</span><span class="s">&#39;url&#39;</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)):</span>
                    <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;organization_not_enought_data&#39;</span><span class="p">)</span>
                    <span class="k">break</span>

        <span class="k">return</span> <span class="n">errors</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.check_sp_certs"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.check_sp_certs">[docs]</a>    <span class="k">def</span> <span class="nf">check_sp_certs</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Checks if the x509 certs of the SP exists and are valid.</span>

<span class="sd">        :returns: If the x509 certs of the SP exists and are valid</span>
<span class="sd">        :rtype: boolean</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">key</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_sp_key</span><span class="p">()</span>
        <span class="n">cert</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_sp_cert</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">key</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">cert</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_sp_key"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_sp_key">[docs]</a>    <span class="k">def</span> <span class="nf">get_sp_key</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the x509 private key of the SP.</span>

<span class="sd">        :returns: SP private key</span>
<span class="sd">        :rtype: string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">key</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="n">key_file</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__paths</span><span class="p">[</span><span class="s">&#39;cert&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="s">&#39;sp.key&#39;</span>

        <span class="k">if</span> <span class="n">exists</span><span class="p">(</span><span class="n">key_file</span><span class="p">):</span>
            <span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">key_file</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span>
            <span class="n">key</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
            <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="k">return</span> <span class="n">key</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_sp_cert"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_sp_cert">[docs]</a>    <span class="k">def</span> <span class="nf">get_sp_cert</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the x509 public cert of the SP.</span>

<span class="sd">        :returns: SP public cert</span>
<span class="sd">        :rtype: string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cert</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="n">cert_file</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__paths</span><span class="p">[</span><span class="s">&#39;cert&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="s">&#39;sp.crt&#39;</span>

        <span class="k">if</span> <span class="n">exists</span><span class="p">(</span><span class="n">cert_file</span><span class="p">):</span>
            <span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">cert_file</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span>
            <span class="n">cert</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
            <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="k">return</span> <span class="n">cert</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_idp_data"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_idp_data">[docs]</a>    <span class="k">def</span> <span class="nf">get_idp_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets the IdP data.</span>

<span class="sd">        :returns: IdP info</span>
<span class="sd">        :rtype: dict</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__idp</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_sp_data"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_sp_data">[docs]</a>    <span class="k">def</span> <span class="nf">get_sp_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets the SP data.</span>

<span class="sd">        :returns: SP info</span>
<span class="sd">        :rtype: dict</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__sp</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_security_data"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_security_data">[docs]</a>    <span class="k">def</span> <span class="nf">get_security_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets security data.</span>

<span class="sd">        :returns: Security info</span>
<span class="sd">        :rtype: dict</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_contacts"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_contacts">[docs]</a>    <span class="k">def</span> <span class="nf">get_contacts</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets contact data.</span>

<span class="sd">        :returns: Contacts info</span>
<span class="sd">        :rtype: dict</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__contacts</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_organization"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_organization">[docs]</a>    <span class="k">def</span> <span class="nf">get_organization</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets organization data.</span>

<span class="sd">        :returns: Organization info</span>
<span class="sd">        :rtype: dict</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__organization</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_sp_metadata"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_sp_metadata">[docs]</a>    <span class="k">def</span> <span class="nf">get_sp_metadata</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets the SP metadata. The XML representation.</span>

<span class="sd">        :returns: SP metadata (xml)</span>
<span class="sd">        :rtype: string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">metadata</span> <span class="o">=</span> <span class="n">OneLogin_Saml2_Metadata</span><span class="o">.</span><span class="n">builder</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__sp</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;authnRequestsSigned&#39;</span><span class="p">],</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;wantAssertionsSigned&#39;</span><span class="p">],</span> <span class="bp">None</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">get_contacts</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_organization</span><span class="p">()</span>
        <span class="p">)</span>
        <span class="n">cert</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_sp_cert</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">cert</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">metadata</span> <span class="o">=</span> <span class="n">OneLogin_Saml2_Metadata</span><span class="o">.</span><span class="n">add_x509_key_descriptors</span><span class="p">(</span><span class="n">metadata</span><span class="p">,</span> <span class="n">cert</span><span class="p">)</span>

        <span class="c"># Sign metadata</span>
        <span class="k">if</span> <span class="s">&#39;signMetadata&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;signMetadata&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">False</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;signMetadata&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">True</span><span class="p">:</span>
                <span class="n">key_file_name</span> <span class="o">=</span> <span class="s">&#39;sp.key&#39;</span>
                <span class="n">cert_file_name</span> <span class="o">=</span> <span class="s">&#39;sp.crt&#39;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="p">(</span><span class="s">&#39;keyFileName&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;signMetadata&#39;</span><span class="p">]</span> <span class="ow">or</span>
                        <span class="s">&#39;certFileName&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;signMetadata&#39;</span><span class="p">]):</span>
                    <span class="k">raise</span> <span class="n">OneLogin_Saml2_Error</span><span class="p">(</span>
                        <span class="s">&#39;Invalid Setting: signMetadata value of the sp is not valid&#39;</span><span class="p">,</span>
                        <span class="n">OneLogin_Saml2_Error</span><span class="o">.</span><span class="n">SETTINGS_INVALID_SYNTAX</span>
                    <span class="p">)</span>
                <span class="n">key_file_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;signMetadata&#39;</span><span class="p">][</span><span class="s">&#39;keyFileName&#39;</span><span class="p">]</span>
                <span class="n">cert_file_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__security</span><span class="p">[</span><span class="s">&#39;signMetadata&#39;</span><span class="p">][</span><span class="s">&#39;certFileName&#39;</span><span class="p">]</span>
            <span class="n">key_metadata_file</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__paths</span><span class="p">[</span><span class="s">&#39;cert&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="n">key_file_name</span>
            <span class="n">cert_metadata_file</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__paths</span><span class="p">[</span><span class="s">&#39;cert&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="n">cert_file_name</span>

            <span class="k">if</span> <span class="ow">not</span> <span class="n">exists</span><span class="p">(</span><span class="n">key_metadata_file</span><span class="p">):</span>
                <span class="k">raise</span> <span class="n">OneLogin_Saml2_Error</span><span class="p">(</span>
                    <span class="s">&#39;Private key file not found: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span>
                    <span class="n">OneLogin_Saml2_Error</span><span class="o">.</span><span class="n">PRIVATE_KEY_FILE_NOT_FOUND</span><span class="p">,</span>
                    <span class="n">key_metadata_file</span>
                <span class="p">)</span>

            <span class="k">if</span> <span class="ow">not</span> <span class="n">exists</span><span class="p">(</span><span class="n">cert_metadata_file</span><span class="p">):</span>
                <span class="k">raise</span> <span class="n">OneLogin_Saml2_Error</span><span class="p">(</span>
                    <span class="s">&#39;Public cert file not found: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span>
                    <span class="n">OneLogin_Saml2_Error</span><span class="o">.</span><span class="n">PUBLIC_CERT_FILE_NOT_FOUND</span><span class="p">,</span>
                    <span class="n">cert_metadata_file</span>
                <span class="p">)</span>

            <span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">key_metadata_file</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span>
            <span class="n">key_metadata</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
            <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">cert_metadata_file</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span>
            <span class="n">cert_metadata</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
            <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="n">metadata</span> <span class="o">=</span> <span class="n">OneLogin_Saml2_Metadata</span><span class="o">.</span><span class="n">sign_metadata</span><span class="p">(</span><span class="n">metadata</span><span class="p">,</span> <span class="n">key_metadata</span><span class="p">,</span> <span class="n">cert_metadata</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">metadata</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.validate_metadata"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.validate_metadata">[docs]</a>    <span class="k">def</span> <span class="nf">validate_metadata</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">xml</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Validates an XML SP Metadata.</span>

<span class="sd">        :param xml: Metadata&#39;s XML that will be validate</span>
<span class="sd">        :type xml: string</span>

<span class="sd">        :returns: The list of found errors</span>
<span class="sd">        :rtype: list</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">xml</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">xml</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&#39;Empty string supplied as input&#39;</span><span class="p">)</span>

        <span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">res</span> <span class="o">=</span> <span class="n">OneLogin_Saml2_Utils</span><span class="o">.</span><span class="n">validate_xml</span><span class="p">(</span><span class="n">xml</span><span class="p">,</span> <span class="s">&#39;saml-schema-metadata-2.0.xsd&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__debug</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="n">Document</span><span class="p">):</span>
            <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">dom</span> <span class="o">=</span> <span class="n">res</span>
            <span class="n">element</span> <span class="o">=</span> <span class="n">dom</span><span class="o">.</span><span class="n">documentElement</span>
            <span class="k">if</span> <span class="n">element</span><span class="o">.</span><span class="n">tagName</span> <span class="o">!=</span> <span class="s">&#39;md:EntityDescriptor&#39;</span><span class="p">:</span>
                <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;noEntityDescriptor_xml&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">valid_until</span> <span class="o">=</span> <span class="n">cache_duration</span> <span class="o">=</span> <span class="n">expire_time</span> <span class="o">=</span> <span class="bp">None</span>

                <span class="k">if</span> <span class="n">element</span><span class="o">.</span><span class="n">hasAttribute</span><span class="p">(</span><span class="s">&#39;validUntil&#39;</span><span class="p">):</span>
                    <span class="n">valid_until</span> <span class="o">=</span> <span class="n">OneLogin_Saml2_Utils</span><span class="o">.</span><span class="n">parse_SAML_to_time</span><span class="p">(</span><span class="n">element</span><span class="o">.</span><span class="n">getAttribute</span><span class="p">(</span><span class="s">&#39;validUntil&#39;</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">element</span><span class="o">.</span><span class="n">hasAttribute</span><span class="p">(</span><span class="s">&#39;cacheDuration&#39;</span><span class="p">):</span>
                    <span class="n">cache_duration</span> <span class="o">=</span> <span class="n">element</span><span class="o">.</span><span class="n">getAttribute</span><span class="p">(</span><span class="s">&#39;cacheDuration&#39;</span><span class="p">)</span>

                <span class="n">expire_time</span> <span class="o">=</span> <span class="n">OneLogin_Saml2_Utils</span><span class="o">.</span><span class="n">get_expire_time</span><span class="p">(</span><span class="n">cache_duration</span><span class="p">,</span> <span class="n">valid_until</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">expire_time</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="nb">int</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">&#39;</span><span class="p">))</span> <span class="o">&gt;</span> <span class="nb">int</span><span class="p">(</span><span class="n">expire_time</span><span class="p">):</span>
                    <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;expired_xml&#39;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">errors</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.format_idp_cert"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.format_idp_cert">[docs]</a>    <span class="k">def</span> <span class="nf">format_idp_cert</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Formats the IdP cert.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__idp</span><span class="p">[</span><span class="s">&#39;x509cert&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__idp</span><span class="p">[</span><span class="s">&#39;x509cert&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">OneLogin_Saml2_Utils</span><span class="o">.</span><span class="n">format_cert</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__idp</span><span class="p">[</span><span class="s">&#39;x509cert&#39;</span><span class="p">])</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.get_errors"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.get_errors">[docs]</a>    <span class="k">def</span> <span class="nf">get_errors</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns an array with the errors, the array is empty when the settings is ok.</span>

<span class="sd">        :returns: Errors</span>
<span class="sd">        :rtype: list</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__errors</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.set_strict"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.set_strict">[docs]</a>    <span class="k">def</span> <span class="nf">set_strict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Activates or deactivates the strict mode.</span>

<span class="sd">        :param xml: Strict parameter</span>
<span class="sd">        :type xml: boolean</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">bool</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__strict</span> <span class="o">=</span> <span class="n">value</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.is_strict"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.is_strict">[docs]</a>    <span class="k">def</span> <span class="nf">is_strict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns if the &#39;strict&#39; mode is active.</span>

<span class="sd">        :returns: Strict parameter</span>
<span class="sd">        :rtype: boolean</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__strict</span>
</div>
<div class="viewcode-block" id="OneLogin_Saml2_Settings.is_debug_active"><a class="viewcode-back" href="../../saml2.html#saml2.settings.OneLogin_Saml2_Settings.is_debug_active">[docs]</a>    <span class="k">def</span> <span class="nf">is_debug_active</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns if the debug is active.</span>

<span class="sd">        :returns: Debug parameter</span>
<span class="sd">        :rtype: boolean</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__debug</span></div></div>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Class Index"
             >modules</a> |</li>
        <li><a href="../../index.html">SAML Python library classes and methods</a> &raquo;</li>
          <li><a href="../index.html" >Class code</a> &raquo;</li>
      </ul>
    </div>
    <div class="footer">
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>
